#ifndef WORKER_H
#define WORKER_H

#include <QObject>
#include <QMutex>
#include <QImage>
#include <opencv2/opencv.hpp>

class Worker : public QObject
{
    Q_OBJECT

public:
    explicit Worker(cv::dnn::Net* openPoseNet = nullptr, QObject* parent = nullptr);
    ~Worker();

public slots:
    void processFrame(cv::Mat frame, bool openPoseLoaded);

signals:
    void frameProcessed(const QImage& image);

private:
    void processFrameWithOpenPose(cv::Mat& frame);
    std::vector<cv::Point> parseOpenPoseOutput(const cv::Mat& output,
        const cv::Size& originalSize,
        float threshold);
    void processOpenPoseOutput(const cv::Mat& output, cv::Mat& image, float threshold);
    QImage convertToQImage(const cv::Mat& frame);

    cv::dnn::Net* openPoseNet;
    QMutex mutex;

    // OpenPose相关常量
    static const std::vector<std::pair<int, int>> POSE_PAIRS;
    static const std::vector<std::string> BODY_PARTS_COCO;

    int H;
    int W;
};



#endif // WORKER_H
